package com.nms.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="t_comment")
public class Comment {

	private String id;
	private News news;
	private User user;
	private Date date;
	private String content;
	
	public Comment(){}
	public Comment(News news,User user){
		this(news,user,new Date());
	}
	public Comment(News news,User user,Date date){
		this.news = news;
		this.user = user;
		this.date = date;
	}
	@Id
	@Column(length=64)
	@GeneratedValue(generator="uuid")
	@GenericGenerator(name="uuid",strategy="uuid")
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	@ManyToOne(fetch=FetchType.EAGER,targetEntity=News.class)
	@JoinColumn(name="target_news_id", referencedColumnName="id")
	public News getNews() {
		return news;
	}
	public void setNews(News news) {
		this.news = news;
	}
	@OneToOne(fetch=FetchType.EAGER,targetEntity=User.class)
	@JoinColumn(name="critics_id", referencedColumnName="id")
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	//@Temporal(value = TemporalType.DATE)
	@Column(name="comment_time")
	public Date getDate() {
		return date;
	}
	
	public void setDate(Date date) {
		this.date = date;
	}
	@Column
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
}
